5 Visualisation of Listings
listings_sf <- st_as_sf(listings, coords = c("longitude", "latitude"), crs = 4326) %>%
st_transform(3414)
# convert coordinates to SVY215.1 Listings across Singapore
## tmap mode set to plotting
tm_shape(listings_sf) +
tm_symbols(col = "planning_region", shape = 21, size = 0.1, border.col = "grey21", border.lwd = 0.5, palette = "Set2") + tm_shape(pln_region_poly) + tm_borders(col = "black", lwd = 1, lty = "solid") + tm_text("REGION_N", size = 0.8)## Warning: The shape pln_region_poly is invalid. See sf::st_is_valid

Here is it clear that most listings are concentrated in the central region.
5.2 Minimum length of stay < 90 & > 90 days
below_90 <- listings_sf %>%
filter(minimum_nights < 90)
above_90 <- listings_sf %>%
filter(minimum_nights > 89)## tmap mode set to plotting
## Warning: The shape pln_region_poly is invalid. See sf::st_is_valid

Many listings are potentially in violation of the law as they require a minimum length of stay of less than 90 nights (red).
5.3 Proximity to MRT stations
## Observations: 183
## Variables: 4
## $ OBJECTID <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1…
## $ STN_NAME <chr> "EUNOS MRT STATION", "CHINESE GARDEN MRT STATION", "KHATIB M…
## $ STN_NO <chr> "EW7", "EW25", "NS14", "NS7", "EW18", "NS5", "EW28", "EW20",…
## $ geometry <POINT [m]> POINT (35782.96 33560.08), POINT (16790.75 36056.3), P…
##
## Attaching package: 'httr'
## The following object is masked from 'package:plotly':
##
## config
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
library(tmap)
# see this page for the ids of all MRT lines in OpenStreetMap
# https://wiki.openstreetmap.org/wiki/Mass_Rapid_Transit_%28Singapore%29
# the downtown line has id '2313458', we can use this to download directly from OSM based on the id
opq_osm_id(id = 2313458, type = "relation") %>%
opq_string() %>%
osmdata_sf() %>%
.$osm_multilines## Simple feature collection with 2 features and 17 fields
## geometry type: MULTILINESTRING
## dimension: XY
## bbox: xmin: 103.7494 ymin: 1.278394 xmax: 103.9659 ymax: 1.412542
## epsg (SRID): 4326
## proj4string: +proj=longlat +datum=WGS84 +no_defs
## osm_id name role
## 2313458-(no role) 2313458 MRT Downtown Line (Bukit Panjang --> Expo) (no role)
## 2313458-inactive 2313458 MRT Downtown Line (Bukit Panjang --> Expo) inactive
## colour from
## 2313458-(no role) #0354a6 Bukit Panjang
## 2313458-inactive #0354a6 Bukit Panjang
## name.en
## 2313458-(no role) MRT Downtown Line (Bukit Panjang --> Expo)
## 2313458-inactive MRT Downtown Line (Bukit Panjang --> Expo)
## name.zh network operator
## 2313458-(no role) 滨海市区线(武吉班让至博览) Singapore Rail SBS Transit
## 2313458-inactive 滨海市区线(武吉班让至博览) Singapore Rail SBS Transit
## public_transport.version ref route to type wheelchair
## 2313458-(no role) 2 DTL subway Expo route yes
## 2313458-inactive 2 DTL subway Expo route yes
## wikidata wikipedia geometry
## 2313458-(no role) Q1663943 en:Downtown MRT line MULTILINESTRING ((103.7569 ...
## 2313458-inactive Q1663943 en:Downtown MRT line MULTILINESTRING ((103.9572 ...
# combine all MRT & LRT lines into a single table
lines <- tribble(
~line, ~id,
"EW East Bound", 445764,
"EW West Bound", 2312796,
"NS North Bound", 445768,
"NS South Bound", 2312797,
"NE", 2293545,
"CC", 2076291,
"DT", 2313458,
"BP LRT", 1159434,
"SK LRT East Loop", 9663107,
"SK LRT West Loop", 1146941,
"PG LRT East Loop", 1146942,
"PG LRT West Loop", 2312984
)
# create a function to download the data from osm based on the relation id
# logic cribbed from https://github.com/ropensci/osmdata/issues/95
download_mrt_line_from_osm <- function(id) {
opq_osm_id(id = id, type = "relation") %>%
opq_string() %>%
osmdata_sf() %>%
.$osm_multilines
}
# apply function to all ids
lines_sf <- map(lines$id, download_mrt_line_from_osm)
# check if we're succesful by plotting a single list element
plot(lines_sf[[7]])## Warning: plotting the first 9 out of 17 attributes; use max.plot = 17 to plot
## all

# combine all lines into a single sf object
# different solutions for this at https://github.com/r-spatial/sf/issues/798
# ignore any warnings that come up
lines_sf <- rbind_list(lines_sf) %>%
st_as_sf(crs = 4326) %>%
st_transform(3414) %>%
mutate_if(is.factor, as.character)## Warning: 'rbind_list' is deprecated.
## Use 'bind_rows()' instead.
## See help("Deprecated")
## Warning in bind_rows_(list_or_dots(...), id = NULL): Vectorizing
## 'sfc_MULTILINESTRING' elements may not preserve their attributes
## Warning in bind_rows_(list_or_dots(...), id = NULL): Vectorizing
## 'sfc_MULTILINESTRING' elements may not preserve their attributes
## Warning in bind_rows_(list_or_dots(...), id = NULL): Vectorizing
## 'sfc_MULTILINESTRING' elements may not preserve their attributes
## Warning in bind_rows_(list_or_dots(...), id = NULL): Vectorizing
## 'sfc_MULTILINESTRING' elements may not preserve their attributes
## Warning in bind_rows_(list_or_dots(...), id = NULL): Vectorizing
## 'sfc_MULTILINESTRING' elements may not preserve their attributes
## Warning in bind_rows_(list_or_dots(...), id = NULL): Vectorizing
## 'sfc_MULTILINESTRING' elements may not preserve their attributes
## Warning in bind_rows_(list_or_dots(...), id = NULL): Vectorizing
## 'sfc_MULTILINESTRING' elements may not preserve their attributes
## Warning in bind_rows_(list_or_dots(...), id = NULL): Vectorizing
## 'sfc_MULTILINESTRING' elements may not preserve their attributes
## Warning in bind_rows_(list_or_dots(...), id = NULL): Vectorizing
## 'sfc_MULTILINESTRING' elements may not preserve their attributes
## Warning in bind_rows_(list_or_dots(...), id = NULL): Vectorizing
## 'sfc_MULTILINESTRING' elements may not preserve their attributes
## Warning in bind_rows_(list_or_dots(...), id = NULL): Vectorizing
## 'sfc_MULTILINESTRING' elements may not preserve their attributes
## Warning in bind_rows_(list_or_dots(...), id = NULL): Vectorizing
## 'sfc_MULTILINESTRING' elements may not preserve their attributes

## Warning in abbreviate_shapefile_names(obj): Field names abbreviated for ESRI
## Shapefile driver
## Warning in CPL_write_ogr(obj, dsn, layer, driver,
## as.character(dataset_options), : GDAL Message 1: One or several characters
## couldn't be converted correctly from UTF-8 to ISO-8859-1. This warning will not
## be emitted anymore.
## tmap mode set to interactive viewing
tm_shape(lines_sf) + tm_lines(col = "colour") + tm_shape(stations) + tm_dots(size = 0.1, col = "yellow") + tm_shape(listings_sf) +
tm_dots(size = 0.02, alpha=0.5) + tm_shape(pln_region_poly) + tm_borders(col = "black", lwd = 1, lty = "solid") + tm_text("REGION_N", size = 0.8)## Warning: The shape pln_region_poly is invalid. See sf::st_is_valid